package com.itheima.controller;

import com.itheima.pojo.entity.Dept;
import com.itheima.pojo.entity.Result;
import com.itheima.service.DeptService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 部门管理Controller
 */
@Slf4j
@RequestMapping("/depts")
@RestController
public class DeptController {
    @Autowired
    private DeptService deptService;

    @GetMapping
    public Result getByDeptList() {
        List<Dept> deptList = deptService.getByDeptList();
        return Result.success(deptList);
    }

    @DeleteMapping
    public Result deleteByDeptId(@RequestParam Integer id){
        log.info("传入部门id：{}",id);
        deptService.deleteByDeptId(id);
        return Result.success();
    }
    @PostMapping
    public Result addDept(@RequestBody Dept dept){
        log.info("传入部门对象：{}",dept);
        deptService.addDept(dept);
        return Result.success();
    }
    @GetMapping("/{id}")
    public Result getByIdDept(@PathVariable Integer id){
        log.info("传入部门id：{}",id);
         Dept dept = deptService.getByIdDept(id);
        return Result.success(dept);
    }
    @PutMapping
     public Result updateDept(@RequestBody Dept dept){
        log.info("传入部门对象：{}",dept);
        deptService.updateDept(dept);
        return Result.success();
     }


}
